package Boss直聘.奥枫.二维数组;

import java.util.ArrayList;
import java.util.Arrays;

public class Main {
    public static void main(String[] args){
        int s [][] = {
                {21,24,53,16,25},
                { 8,27,14, 3,65},
                {15,24, 7,14,13},
                {85,16, 4,12,41},
                { 8,37,32,18, 1}
        };
        int x=0,y=0;
        int a = function(s,0,0);
        System.out.println(a);
    }

    private static int function(int[][] s, int x, int y) {
        ArrayList<Integer> a = new ArrayList<Integer>();
        a.add(s[x][y]);
        int as[] = {};
        if(x-1>=0){//x
            if(y-1>=0){//x比最小值大
                a.add(s[x-1][y-1]);
                a.add(s[x][y-1]);
                a.add(s[x-1][y]);
            }
            if (y+1<s[0].length){
                a.add(s[x-1][y+1]);
                a.add(s[x][y+1]);
            }
        }
        if(x+1<s.length){//x比最大值小
            if(y-1>=0){
                a.add(s[x+1][y-1]);
                a.add(s[x+1][y]);
            }
            if (y+1<s[0].length){
                a.add(s[x+1][y+1]);
            }
        }
        Integer[] objects = a.toArray(new Integer[0]);
        Arrays.sort(objects);
        return objects[0];
    }

    

}
